/**
 * Created by lwy on 2017/8/21.
 */


var page = 1;


function doAjax(){
    $.ajax({
        url:'/crm/refundLogC/search.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            pageNum:page,
            userName:$('#userName').val(),
            realName:$('#realName').val(),
            code:$('#code').val(),
            referCode:$('#referCode').val(),
            refundStateValue:$('#refundStateValue').val(),
        },
        type:'post',
        success: function (data) {
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg);
            }
            if(data.code==1){
                $('#record').html(data.datas.recordsTotal);
                $('#withdraw-record').empty();
                for(var i=0;i<data.datas.refundList.length;i++){
                    $('<tr class="gradeA odd">'+
                        '<a href=""><td class="sorting_1 withdrawId" style="text-decoration: underline;cursor: pointer;">'+data.datas.refundList[i].id+'</td></a>'+
                        '<td class=" ">'+data.datas.refundList[i].code+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].referCode+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].goodsOrderCode+'</td>'+
                        '<td class="sorting_1">'+data.datas.refundList[i].userName+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].realName+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].shopName+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].goodsName+'</td>'+
                        '<td class="center">'+data.datas.refundList[i].specificationName+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].refundMoney+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].num+'</td>'+
                        '<td class=" ">'+data.datas.refundList[i].refundState+'</td>'+
                        '</tr>').appendTo($('#withdraw-record'));
                }

                $('.withdrawId').click(function(){
                    var id = $(this).html();
                    window.location.href="/crm/refundLogC/detail?id="+id;

                })

                $(".pagination").createPage({
                    totalPage:data.datas.totalPage,
                    currPage:data.datas.pageNo,
                    pageCount:data.datas.pageNo,
                    turndown:'true',
                    backFn:function(p){
                        page=p;
                        doAjax();
                    }
                });
            }
        }
    })
}

$(function(){
    doAjax();
})

//查询
$('#refer').click(function(){
    page=1;
    doAjax();
})
